function [Jx_f, Jy_f]= RightAngle2(Jx, Jy,J_sign,XL,YL,current)
    N=5+randi(10);    
    x=zeros(1,N);
    y=zeros(1,N);

    x(1)=1;
    y(1)=100+randi(500);

    w=10+randi(5);
    
    x(2)=150;
    y(2)=y(1);
    
    J(y(2)-w:y(2)+w,x(1):x(2))=1;
    Jx(y(2)-w:y(2)+w,x(1):x(2))=J_sign*current;

for i=3:N-1 
    if mod(i,2)==0
        x(i)=x(i-1)+10+randi(round((XL-100-x(i-1))*(i)/N));
        y(i)=y(i-1);
        Jx(y(i)-w:y(i)+w,x(i-1)-w:x(i)+w)=J_sign*current;
    elseif mod(i,2)==1
        x(i)=x(i-1);
        y(i)=100+randi(round((YL-200-y(i+1))));
        if y(i-1) < y(i)
            J(y(i-1):y(i),x(i)-w:x(i)+w)=1;
            Jy(y(i-1):y(i),x(i)-w:x(i)+w)=J_sign*current;
        else
            J(y(i):y(i-1),x(i)-w:x(i)+w)=1;
            Jy(y(i):y(i-1),x(i)-w:x(i)+w)=J_sign*-1*current;
        end
    end
    
end
x(N)=XL;
y(N)=y(N-1);

Jx(y(N)-w:y(N)+w,x(N-1):x(N))=J_sign*current;


Jx_f=imgaussfilt(Jx,.8);
Jy_f=imgaussfilt(Jy,.8);